package com.ksd.modules.course.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.course.po.AdminCourseCommentSavePO;
import com.ksd.modules.course.po.AdminCourseCommentSearchPO;
import com.ksd.modules.course.service.IAdminCourseCommentService;
import com.ksd.modules.course.vo.AdminCourseCommentVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminCourseCommentController extends BaseController {
    
    @Autowired
    private IAdminCourseCommentService adminCourseCommentService;

    /**
     * 【课程】-【评论】-列表
     * @return
     */
    @PostMapping("/course/comment/list")
    public R<Page<AdminCourseCommentVo>> findAdminCourseCommentComments(@Validated @RequestBody AdminCourseCommentSearchPO adminCourseSearchPO){
        return R.data(adminCourseCommentService.findAdminCourseComments(adminCourseSearchPO));
    }


    /**
     * 【课程】-【评论】-保存和更新
     * @param adminCourseSavePO
     * @return
     */
    @PostMapping("/course/comment/saveupdate")
    @ApiLog("【课程】-【评论】-保存和更新")
    @RepeatSubmit
    public R<AdminCourseCommentVo> saveUpdateAdminCourseCommentComment(@Validated @RequestBody AdminCourseCommentSavePO adminCourseSavePO){
        return R.data(adminCourseCommentService.saveUpdateAdminCourseComment(adminCourseSavePO));
    }

    /**
     * 【课程】-【评论】-根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/course/comment/get/{id}")
    public R<AdminCourseCommentVo> getAdminCourseCommentCommentById(@PathVariable("id")Long id){
        return R.data(adminCourseCommentService.getAdminCourseCommentById(id));
    }

    /**
     * 【课程】-【评论】-批量物理删除
     *
     * @return
     */
    @PostMapping("/course/comment/batch/remove")
    @ApiLog("【课程】-【评论】-批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminCourseCommentComment(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminCourseCommentService.batchRemovesAdminCourseComment(batchIdsPO));
    }

    /**
     * 【课程】-【评论】-根据ID删除
     * @param id
     * @return
     */
    @PostMapping("/course/comment/remove/{id}")
    @ApiLog("【课程】-【评论】-根据ID删除")
    public R<Boolean> removeAdminCourseCommentCommentById(@PathVariable("id")Long id){
        return R.data(adminCourseCommentService.removeAdminCourseCommentById(id));
    }

    /**
     * 【课程】-【评论】-修改状态
     *
     * @return
     */
    @PostMapping("/course/comment/status/{id}/{field}")
    @ApiLog("【课程】-【评论】-修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminCourseCommentService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminCourseCommentService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【课程】-批量上架
     *
     * @return
     */
    @PostMapping("/course/comment/batch/up")
    @ApiLog("【课程】-批量上架")
    @RepeatSubmit
    public R<Boolean> batchUps(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminCourseCommentService.batchUps(batchIdsPO));
    }

    /**
     * 【课程】-批量下架
     *
     * @return
     */
    @PostMapping("/course/comment/batch/down")
    @ApiLog("【课程】-批量下架")
    @RepeatSubmit
    public R<Boolean> batchDowns(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminCourseCommentService.batchDowns(batchIdsPO));
    }
}
